﻿<?php
if (!isset($_SESSION["taikhoan"]))
	{
		header("Location: dbcl-dangnhap.php");
	}
	include "connect.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="calendar/calendar_themes/default/style.css" />
<script language="javascript" src="calendar/popcalendar.js"></script>
<script language="javascript">
	function checkTime()
	{
		var batdau = document.getElementById("txtBatDau").value;
		var ketthuc = document.getElementById("txtKetThuc").value;
		if(batdau != "" && ketthuc != "")
		{
			batdauArr = batdau.split('-');
			ketthucArr = ketthuc.split('-');
			
			if(batdauArr[0] <= ketthucArr[0])
			{
				if(batdauArr[1] <= ketthucArr[1] )
				{
					if(batdauArr[2] < ketthucArr[2])
					{
						return true;
					}
					else
					{
						return false;
					}
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	function checkFormOK()
	{
		if(checkTime() == false)
		{
			alert("Ngay bat dau khong dc lon hon ngay ket thuc");
			return false;
		}
		return true;
	}
</script>
</head>

<body>

<form name="f" method="post" action="" onsubmit="return checkFormOK();">
			<table width="500" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0">
						
					  <tr> 
							<td height="30" colspan="2" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
								<span style="font-size:24px; color:#FFFFFF; font-weight:bold;">Cập Nhật Thời Gian</span></td>
					  </tr>
					  
					  <tr bordercolor="#FFFFFF" align="center"> 
						  <td  height="15" width="200" colspan="2"></td>
						 
					  </tr>
						
					  <tr bordercolor="#FFFFFF" align="center"> 
						  <td  height="30" style="font-size:18px" width="200">Công Việc:</td>
						 <td align="left">
						                 <select name="cv">
										          
												           <?php 
														       $sql=mysql_query("select ma_quyen,ten_quyen from quyen where ma_quyen !='DBCL' and ma_quyen !='AD' ");
															   while ($r=mysql_fetch_row($sql))
															      {
																       $cv=$r[0];
																	   $tencv=$r[1];
																	  ?>
																	  <option value="<?php echo $cv; ?>"><?php echo $tencv; ?></option>
																	  <?php
																   }
														   ?>
												  
										 </select>
						 </td>
					  </tr>
					  
					  <tr bordercolor="#FFFFFF" align="center"> 
						  <td  height="30" style="font-size:18px"> Thời Gian Bắt Đầu </td>
						 <td align="left">
                         	<input type="text" name="txtBatDau" id="txtBatDau" value="" onclick="popCalendar.show(this, 'txtBatDau', 'yyyy-mm-dd', true);" />
                         </td>
					  </tr>
					  
					   <tr bordercolor="#FFFFFF" align="center"> 
						  <td  height="30" style="font-size:18px"> Thời Gian Kết Thúc </td>
						 <td align="left">
                         	<input type="text" name="txtKetThuc" id="txtKetThuc" value="" onclick="popCalendar.show(this, 'txtKetThuc', 'yyyy-mm-dd', true);" />
                         </td>
					  </tr>
					  
					  <tr bordercolor="#FFFFFF" align="center"> 
						  <td  height="15"  colspan="2">
                          </td>
						 
					  </tr>
					  
					  <tr bordercolor="#FFFFFF">
						  <td  align="right" height="30"><input type="submit" value="Lưu Lại" name="luu" /></td>
						  <td align="center"><input type="reset" value="Làm Lại" name="huy" /></td>
					 </tr>
					 <tr bordercolor="#FFFFFF" align="center"> 
						  <td  height="15"  colspan="2"></td>
						 
					  </tr>
					
			</table>
</form>
<?php
           if(isset($_POST["luu"]))
				{
				          $sql=mysql_query("select ma_hknk from `hocki nienkhoa` where ma_hknk=(select max(ma_hknk) from `hocki nienkhoa`)");
						  $r=mysql_fetch_row($sql);
				          $hknk=$r[0];
				          $bd=$_POST["txtBatDau"];
						  $kt=$_POST["txtKetThuc"];
						  $cv=$_POST["cv"];
						  $s=mysql_query("select * from `thoi gian danh gia` where ma_hknk='$hknk' and congviec='$cv'");
						  $count=mysql_num_rows($s);
						  if ($count>0)  $k=mysql_query("update `thoi gian danh gia` set ngay_batdau='$bd',ngay_ketthuc='$kt' where ma_hknk='$hknk' and congviec='$cv'");
						  else
						            $kq=mysql_query(" insert into `thoi gian danh gia` values('$bd','$kt','$cv','$hknk' )");
						  echo"<script type='text/javascript'>alert('Them Thanh Cong')</script>";
		                  echo'<meta http-equiv="refresh" content="0;URL=dbcl-capnhat.php?nav=cntg">';
						  
				}
 ?>		

</body>
</html>


